package com.bkgy.controller.allprocess.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bkgy.controller.allprocess.dto.*;
import com.bkgy.controller.allprocess.entity.*;
import com.bkgy.controller.allprocess.mapper.AllProcessMachineMapper;
import com.bkgy.controller.allprocess.service.AllProcessMachineService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;


@Service
public class AllProcessMachineServiceImpl  implements AllProcessMachineService {

    @Autowired
    private AllProcessMachineMapper allProcessMachineMapper;

    /**
     * 全流程成材率模型首页 机组成材率
     * @param request_get AllpricessIndexReasonRequst
     * @return AllProcessIndexDetails
     */
    public  ResultData<AllProcessIndexDetails> getAllprocessMachines (AllpricessIndexReasonRequst request_get) {
        //日期转换与赋值
        AllpricessIndexReasonRequst request = setdatetime(request_get);

        try {
            Page<?> page = new Page<>(request.getPageIndex(), request.getPageSize());

            //总行数数
            int count = 0;

            // 构建响应对象
            AllProcessIndexDetails indexdetails = new AllProcessIndexDetails();

            //机组计算成材率
            List<TbAllpricessIndexEntity> results = new ArrayList<>();
            if(request_get.getLinename()==null)
            {
                request_get.setLinename("all");
                count = results.size();
            }
            if(request.getLinename().equals("all"))
            {
                results = allProcessMachineMapper.gettAllProcessIndexDetails(page, request);
                count = 7;
            }
//            else if(request.getLinename().equals("cal1630"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetails1630(page, request);
//                count = results.size();
//            }
//            else if(request.getLinename().equals("cal2150"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetails2150(page, request);
//                count = results.size();
//            }
//            else if(request.getLinename().equals("cgl1870"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetails1870(page, request);
//                count = results.size();
//            }
//            else if(request.getLinename().equals("tcm2280"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetails2280(page, request);
//                count = results.size();
//            }
//            else if(request.getLinename().equals("rcl1630"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetailsRcl1630(page, request);
//                count = results.size();
//            }
//            else if(request.getLinename().equals("rcl2150"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetailsRcl2150(page, request);
//                count = results.size();
//            }
//            else if(request.getLinename().equals("rcl1870"))
//            {
//                results = allProcessMachineMapper.gettAllProcessIndexDetailsRcl1870(page, request);
//                count = results.size();
//            }
            indexdetails.setUnitCalculationYield(results);

            return ResultData.ResultDataSuccess(indexdetails, count);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("获取失败" + e.getMessage(), null);
        }
    }

    /**
     * 根据前台传入查询开始和查询结束日期，构造出yyyymmddhhmmss数据查询
     * @param request_get AllpricessIndexReasonRequst
     * @return TbAllpricessIndexEntity
     */
    public AllpricessIndexReasonRequst setdatetime(AllpricessIndexReasonRequst request_get) {
        try {

            String dbegin_Times = request_get.getDbegin().substring(0,10);
            request_get.setDbegin(dbegin_Times);//时间格式：2025-07-03


            String endTime_Times = request_get.getDend().substring(0,10);
            request_get.setDend(endTime_Times);//时间格式：2025-07-03

        } catch (Exception e) {
            e.printStackTrace();
        }
        return request_get;
    }


}
